package ecommerce.user;

import ecommerce.dao.BookDao;
import ecommerce.model.Address;
import ecommerce.model.Book;
import ecommerce.model.Category;
import ecommerce.model.Customer;
import ecommerce.model.Item;
import ecommerce.model.MethodPayment;
import ecommerce.model.Order;
import ecommerce.model.Payment;
import ecommerce.model.Phone;
import ecommerce.service.EcommerceService;
import java.util.Date;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;



public class UserTest {
    public static void main(String [] args){
        ApplicationContext applicationContext = new
                ClassPathXmlApplicationContext("applicationContext.xml");

        EcommerceService bs = (EcommerceService)applicationContext.getBean("bookService");
        Book buku = new Book();
        //BookDao bookDao = (BookDao) applicationContext.getBean("bookDao");

        Category c = new Category();
        c.setName("berita");
        c.setDescription("emansipasi wanita");
        bs.save(c);

        buku.setJudul("Habislah gelap terbitlah Terang");
        buku.setPenerbit("Gramedia");
        buku.setPenulis("Kartini");
        buku.setCategory(c);
       bs.save(buku);

       Address ad = new Address();
       ad.setKodePos(10220);
       ad.setProvinsi("DKI Jakarta");
       ad.setTown("jakarta pusat");
       

       Item item = new Item();
        item.setJumlah(3);
        item.setBook(buku);
        item.setSubtotalPrice(20000);
        bs.save(item);

        Phone phone = new Phone();
        phone.setGsmNumber("08569494949");


        Customer customer = new Customer();
        customer.setName("hadi");
        customer.setUsername("khawanz");
        customer.setAge(20);
        customer.setPhone(phone);
        customer.setEmail("kd_kurnia");
        customer.setPassword("mil");
        customer.setSex('l');
        customer.setAddress(ad);
      
        bs.save(customer);

        Order order = new Order();
        order.setCustomer(customer);
        order.setStatus(false);
        order.setTanggal(new Date());
        bs.save(order);


        Payment p = new Payment();
        p.setCustomer(customer);
        p.setOrder(order);
        p.setMethod(MethodPayment.COD);
        bs.save(p);

       Book b = (Book)bs.getBook(1L);
       Item it = (Item)bs.getItem(1L);
       Customer cus = (Customer)bs.getCustomer(1L);
       Order o = (Order)bs.getOrder(1L);
      Payment pay = (Payment)bs.getPayment(1L);
       
       System.out.println("Judul:"+ b.getJudul());
       System.out.println("Penerbit: "+b.getPenerbit());
       //System.out.println("Penerbit: "+b.getPenerbit());
       System.out.println("item ID: "+it.getId());
       System.out.println("Customer ID: "+cus.getId());
       System.out.println("Customer phone: "+cus.getPhone().getGsmNumber());
       System.out.println("Order ID: "+o.getId());
       System.out.println("Payment ID: "+pay.getId());
       System.out.println(""+pay.getCustomer().getAddress().getProvinsi());

        //bookDao.save(buku);

       
    }
}